package com.java.websocket.util;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by PIRATE on 2016/1/27.
 */
public class TimeUtil {
    public static String getCurrentTime(String... format){
        if(format == null || format.length == 0){
            return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        }else{
            String timeFormat = format[0];
            return new SimpleDateFormat(timeFormat).format(new Date());
        }
    }

    public static String formatTime(Date date,String format){
        if(format == null){
            format = "yyyy-MM-dd HH:mm:ss";
        }
        return new SimpleDateFormat(format).format(date);
    }

    public static  boolean isSameDay(long date1,long date2){
        Date date = new Date(date1);
        Date date3 = new Date(date2);
        if(formatTime(date,"yyyyMMdd").equals(formatTime(date3,"yyyyMMdd"))){
            return true;
        }else{
            return false;
        }
    }

    public static long getCurrentLongTime(){
        return new Date().getTime();
    }
}
